/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 
	/// module : levelLogic
	/// </summary>
	public class LevelRegionSavePOD : IPOD 
    {
        public readonly static Func<LevelRegionSavePOD> FACTORY = () => new LevelRegionSavePOD();
		public static Func<LevelRegionSavePOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
        private List<LevelEntityPOD> m_modifiedEntities;
		/// <summary>
        /// 
        /// </summary>
        private List<int> m_effectCids;
		/// <summary>
        /// audio.Id, 策划自定义bgm，优先级最高，0表示没有，-1表示静音
        /// </summary>
		public int customBgmCid;
		/// <summary>
        /// 天气类型，key是天气id，为0时表示全局天气
        /// </summary>
        private Dictionary<int, int> m_customWeathers;
		
		
        public List<LevelEntityPOD> modifiedEntities
        {
            get
            {
                if(m_modifiedEntities == null)
                {
                    m_modifiedEntities = new();
                }
                return m_modifiedEntities;
            }
            private set => m_modifiedEntities = value;
        }
        public List<LevelEntityPOD> unsafe_modifiedEntities
        {
        	get => m_modifiedEntities;
        	set => m_modifiedEntities = value;
        }
        public List<int> effectCids
        {
            get
            {
                if(m_effectCids == null)
                {
                    m_effectCids = new();
                }
                return m_effectCids;
            }
            private set => m_effectCids = value;
        }
        public List<int> unsafe_effectCids
        {
        	get => m_effectCids;
        	set => m_effectCids = value;
        }
        public Dictionary<int, int> customWeathers
        {
            get
            {
                if(m_customWeathers == null)
                {
                    m_customWeathers = new();
                }
                return m_customWeathers;
            }
            private set => m_customWeathers = value;
        }
        public Dictionary<int, int> unsafe_customWeathers
        {
        	get => m_customWeathers;
        	set => m_customWeathers = value;
        }
		
		/*-- constructors --*/
		public LevelRegionSavePOD() {}
		public LevelRegionSavePOD(List<LevelEntityPOD> modifiedEntities, List<int> effectCids, int customBgmCid, Dictionary<int, int> customWeathers) {
			this.m_modifiedEntities = modifiedEntities;
			this.m_effectCids = effectCids;
			this.customBgmCid = customBgmCid;
			this.m_customWeathers = customWeathers;
		}
		  public void Serial(SOutputStream _out) {
                if(m_modifiedEntities != default) {
                    _out.WriteByte(1);
                    _out.Write_list_pod(m_modifiedEntities);
                }
                if(m_effectCids != default) {
                    _out.WriteByte(2);
                    _out.Write_list_int(m_effectCids);
                } 
                if(customBgmCid != default) {
                    _out.WriteByte(3);
                    _out.Write_int(customBgmCid);
                }
                if(m_customWeathers != default) {
                    _out.WriteByte(4);
                    _out.Write_map_int_int(m_customWeathers);
                }
        }
            
        public void UnSerial(SInputStream _in) {
            while (_in.HasRemaining())
            {
                int _key = _in.ReadByte();
                switch (_key)
                {
                    case 1:
                        m_modifiedEntities = _in.Read_list_pod<LevelEntityPOD>(LevelEntityPOD.DynamicFactory);
                        break;
                    case 2:
                        m_effectCids = _in.Read_list_int();
                        break;
                    case 3:
                        customBgmCid = _in.Read_int();
                        break;
                    case 4:
                        m_customWeathers = _in.Read_map_int_int();
                        break;
                    default: _in.SkipBinary();break;
                }
            }
        }
		
		public LevelRegionSavePOD Clone() {
            LevelRegionSavePOD o = DynamicFactory();
            if (m_modifiedEntities != null) {
                o.m_modifiedEntities = m_modifiedEntities.ConvertAll(o => o?.Clone());
            }
            if (m_effectCids != null) {
                o.m_effectCids = new (m_effectCids);
            }
            o.customBgmCid = customBgmCid;
            if (m_customWeathers != null) {
                o.m_customWeathers = new (m_customWeathers);
            }
            return o;
        }
        
        public void Clear() {
            m_modifiedEntities = default;
            m_effectCids = default;
            customBgmCid = default;
            m_customWeathers = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "LevelRegionSavePOD [";
			str += "modifiedEntities=";
			str += m_modifiedEntities.ToString<LevelEntityPOD>();
			str += ", effectCids=";
			str += m_effectCids.ToString<int>();
			str += ", customBgmCid=";
			str += customBgmCid;
			str += ", customWeathers=";
			str += m_customWeathers.ToString<int, int>();
			str += "]";
			return str;
		}
		
	}
}